home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / r_speed1d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.6 KB  |  252 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef DOUBLE
  12.  
  13. typedef double this_type;
  14.  
  15. #define        TOLERANCE        DTOLERANCE
  16. #define        THIS_GEN        dgen_
  17. #define        THIS_FFTI        dfft1di
  18. #define        THIS_FFT        dfft1d
  19. #define        THIS_FFTU        dfft1du
  20. #define        THIS_SCAL        dscal1d
  21.  
  22. #endif
  23.  
  24. #ifdef SINGLE
  25.  
  26. typedef float this_type;
  27.  
  28. #define        TOLERANCE        STOLERANCE
  29. #define        THIS_GEN        sgen_
  30. #define        THIS_FFTI        sfft1di
  31. #define        THIS_FFT        sfft1d
  32. #define        THIS_FFTU        sfft1du
  33. #define        THIS_SCAL        sscal1d
  34.  
  35. #endif
  36.  
  37. /*    */
  38.  
  39. void inimat_();
  40. void GetArguments();
  41. void get_values();
  42.  
  43. int min_size, max_size, inc_size, is_parallel, timing;
  44. this_type *pa, *pSave;
  45.  
  46. static     long z_sec, z_usec;
  47. static int first_time = 1;
  48.  
  49. float second()
  50. {
  51.         struct timeval s_val;
  52.     struct timezone s_z;
  53.     float time;
  54.     long n_sec, n_usec;
  55.         gettimeofday(&s_val, &s_z);
  56.     n_sec = s_val.tv_sec;
  57.     n_usec = s_val.tv_usec;
  58.     if( first_time ) {
  59.         z_sec = n_sec;
  60.         z_usec = n_usec;
  61.         first_time =0;
  62.     }
  63.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  64.     return( time );
  65. }
  66.  
  67. main(argc,argv)
  68. int argc;
  69. char *argv[];
  70. {
  71.     int i, j, k, n_total, is_wrong, size, inc, n_times, n_flops;
  72.     double x, y, t, emax;
  73.     this_type ratio;
  74.  
  75. /* ******************************************************* */
  76.     GetArguments( argc, argv);
  77. /* ******************************************************* */
  78.  
  79.     srandom( (123*getpid()) | 0x01);
  80.  
  81.     for( size=min_size ; size <= max_size ; size *= inc_size) { 
  82.  
  83.     n_total = ((size+2)*MAX_STRIDE);
  84.     pa = (this_type *)malloc( (n_total + size + FACTOR_SPACE) * sizeof(this_type));
  85.     if( !(pa) ) {
  86.         fprintf( stderr, "Could not allocate ... Exiting\n");
  87.         exit (-1);
  88.     }
  89.  
  90.     fflush(stdout);
  91.  
  92.     printf( "%4d  ", size);
  93.  
  94.     n_flops = (int) (5. * (double)(size/2) * (log((double)(size/2))/log(2.)));
  95.     n_times = (int) (MAX_FLOPS / (double)(2*n_flops));
  96.     if(n_times < 1) n_times =1;
  97.     ratio = 1./(double)size;
  98. /* *******************************************************
  99.     PACKED --- stride 1
  100.     inc = 1;
  101.     n_total = ((size+2)*inc);
  102.     pSave = pa + n_total;
  103.  
  104.     THIS_GEN(pa, &n_total);
  105.     pSave = THIS_FFTI( size, pSave);
  106.  
  107.     t = second();
  108.     for ( i = 0 ; i < n_times ; i++)  {
  109.         
  110.         is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
  111.         is_wrong = THIS_FFT(  1, size, pa, inc, pSave);
  112.         THIS_SCAL( size, ratio, pa, inc);
  113.     }
  114.     t = second() - t;
  115.     if( timing)
  116.         x = t / (double)(2*n_times);
  117.     else
  118.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  119.     printf("%6.4e  ", x);
  120. ******************************************************* */
  121. /* *******************************************************
  122.     ALMOST_PACKED --- stride 1
  123. ******************************************************* */
  124.     inc = 1;
  125.     n_total = ((size+2)*inc);
  126.     pSave = pa + n_total;
  127.  
  128.     THIS_GEN(pa, &n_total);
  129.     pSave = THIS_FFTI( size, pSave);
  130.  
  131.     t = second();
  132.     for ( i = 0 ; i < n_times ; i++)  {
  133.         
  134.         is_wrong = THIS_FFTU( -1, size, pa, inc, pSave);
  135.         is_wrong = THIS_FFTU(  1, size, pa, inc, pSave);
  136.         THIS_SCAL( size, ratio, pa, inc);
  137.     }
  138.     t = second() - t;
  139.     if( timing)
  140.         x = t / (double)(2*n_times);
  141.     else
  142.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  143.     printf("%6.4e  ", x);
  144. /* *******************************************************
  145.     PACKED --- stride > 1
  146.  
  147.     inc =  MAX_STRIDE;
  148.     n_total = ((size+2)*inc);
  149.     pSave = pa + n_total;
  150.  
  151.     THIS_GEN(pa, &n_total);
  152.     pSave = THIS_FFTI( size, pSave);
  153.  
  154.     t = second();
  155.     for ( i = 0 ; i < n_times ; i++)  {
  156.         
  157.         is_wrong = THIS_FFT( -1, size, pa, inc, pSave);
  158.         is_wrong = THIS_FFT(  1, size, pa, inc, pSave);
  159.         THIS_SCAL( size, ratio, pa, inc);
  160.     }
  161.     t = second() - t;
  162.     if( timing)
  163.         x = t / (double)(2*n_times);
  164.     else
  165.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  166.     printf("%6.4e  ", x);
  167. ******************************************************* */
  168. /* *******************************************************
  169.     ALMOST_PACKED --- stride > 1
  170. ******************************************************* */
  171.     inc =  MAX_STRIDE;
  172.     n_total = ((size+2)*inc);
  173.     pSave = pa + n_total;
  174.  
  175.     THIS_GEN(pa, &n_total);
  176.     pSave = THIS_FFTI( size, pSave);
  177.  
  178.     t = second();
  179.     for ( i = 0 ; i < n_times ; i++)  {
  180.         
  181.         is_wrong = THIS_FFTU( -1, size, pa, inc, pSave);
  182.         is_wrong = THIS_FFTU(  1, size, pa, inc, pSave);
  183.         THIS_SCAL( size, ratio, pa, inc);
  184.     }
  185.     t = second() - t;
  186.     if( timing)
  187.         x = t / (double)(2*n_times);
  188.     else
  189.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  190.     printf("%6.4e  ", x);
  191. /* *******************************************************
  192. ******************************************************* */
  193.     printf("\n");
  194.     free(pa);
  195.     }
  196.     return (0);
  197. }
  198.  
  199. int is_random;
  200.  
  201. void GetArguments( argc, argv)
  202. int argc;
  203. char *argv[];
  204. {
  205.     int i, j, k;
  206.     int nerror = 0;
  207.  
  208. #define ON    1
  209.  
  210.     max_size = MAX_SIZE;
  211.     min_size = MIN_SIZE;
  212.     inc_size = INC_SIZE;
  213.  
  214.     is_parallel = 0;
  215.     timing = 0;
  216.  
  217. /* ******************************************************* */
  218.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  219.     if( argv[i][0] == '-') {
  220.         switch ( argv[i][1]) {
  221.         case 's' :
  222.         case 'S' :  
  223.                 is_parallel = 0;
  224.                 break;
  225.         case 'p' :
  226.         case 'P' :  
  227.                 is_parallel = 1;
  228.                 break;
  229.         case 't' :
  230.         case 'T' :  
  231.                 timing = 1;
  232.                 break;
  233.         default  :  nerror = ON;
  234.         }
  235.     }
  236.     else {
  237.         if( i+1 > argc)
  238.         nerror = ON;
  239.         else { 
  240.         min_size = atoi( argv[i++]);
  241.         max_size = atoi( argv[i++]);
  242.         inc_size = atoi( argv[i]);
  243.         }
  244.     }
  245.     }
  246.     if( nerror == ON) {
  247.     fprintf( stderr, 
  248.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  249.     exit(-1);
  250.     }
  251. }
  252.